package com.feri.rbacsys.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.feri.rbacsys.entity.Buyorder;
import com.feri.rbacsys.vo.BuyAmounVo;
import com.feri.rbacsys.vo.BuyorderVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 神经质的木子李
 * @description 针对表【t_buyorder】的数据库操作Mapper
 * @createDate 2023-03-28 15:31:29
 * @Entity com.feri.rbacsys.entity.Buyorder
 */
public interface BuyorderMapper extends BaseMapper<Buyorder> {
    @Select("select p.id,p.name,p.picture,p.price,b.buy_stock buyStock, b.price purchasePrice,(b.buy_stock*b.price) as total from t_product p inner join t_buyorder b on p.name=b.product_name")
    List<BuyorderVo> getall();

//    @Select("select p.id,p.name from t_buyorder b \n" +
//            "inner join t_product p \n" +
//            "on b.product_name=p.name\n" +
//            "where p.id=#{productId}")
//    ProductVo selByName(Integer productId);

    @Select("select sum(buy_stock) buyAmount from t_buyorder where product_id=#{productId}")
    BuyAmounVo getAmout(Integer productId);

}




